<template>
  <div>
    <el-button type="primary" plain @click="dialogVisible = true;"
               style="position: absolute;left: 330px;top: 80px;">添加</el-button>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%">
      <el-input placeholder="请输入小说类型" v-model="typeadd.name" style="width: 300px"></el-input>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="add()">确 定</el-button>
  </span>
    </el-dialog>
  <div>
    <br>
    <br>
    <el-table
      :data="tableData"
      stripe
      style="width: 100%">
      <el-table-column
        prop="tid"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="类型名称"
        width="180">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-edit"
            @click="dialogFormVisible=true;typeupdate=scope.row"></el-button>
          <el-button
            size="mini"
            type="danger" icon="el-icon-delete"
            @click="del(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      small
      layout="total,prev, pager, next"
      :page-size="pageSize"
      :total="total" @current-change="page">
    </el-pagination>

    <el-dialog title="纸质修改" :visible.sync="dialogFormVisible">
      <el-form :model="typeupdate">
        <el-form-item label="编号">
          <el-input v-model="typeupdate.tid" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="名称" >
          <el-input v-model="typeupdate.name" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="upd()">确 定</el-button>
      </div>
    </el-dialog>

  </div>
  </div>
</template>

<script>
export default {
  name: "Type",
  data(){
   return {
     total: 0,
     pageSize: 6,
     tableData: [],
     typeadd:{name:""},
     dialogVisible: false,
     dialogFormVisible:false,
     typeupdate:{}
   }
  },
  created() {
   this.find()
  },
  methods:{
   find(){
     this.$http.post("/backservice/type/findpage?pageNum=0&pageSize=" + this.pageSize).then(response => {
       console.log(response.userList)
       this.tableData = response.userList
       this.total = response.TotalNum
     })
   },
    page(currentPage) {
      this.$http.post('/backservice/type/findpage?&pageNum=' + (currentPage - 1) + '&pageSize=' + this.pageSize)
        .then(response => {
          this.tableData = response.userList
        })
    },
    add(){
     this.dialogVisible=false
     this.$http.post("/backservice/type/add",this.typeadd).then(data=>{
       if (data>0){
         this.find()
         alert("添加成功")
       }else {
         alert("添加失败")
       }
     })
    },

    upd(){
     this.dialogFormVisible=false
      this.$http.post("/backservice/type/update",this.typeupdate).then(data=>{
        if (data>0){
          this.find()
          alert("修改成功")
        }else {
          alert("修改失败")
        }
      })
    },
    del(row){
      this.$http.post("/backservice/type/delete",{tid:row.tid}).then(data=>{
        if (data>0){
          this.find()
          alert("删除成功")
        }else {
          alert("删除失败")
        }
      })
    }

  }
}
</script>

<style scoped>

</style>
